package com.telit.uav.service.impl;

import com.telit.uav.dao.CommTeamUserDao;
import com.telit.uav.dto.TeamMemberDTO;
import com.telit.uav.entity.CommTeamUser;
import com.telit.uav.service.TeamUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashSet;
import java.util.Set;


/**
 * @Auther amy
 * @Describe
 */
@Service
public class TeamUserServiceImpl implements TeamUserService {

    @Autowired
    private CommTeamUserDao commTeamUserDao;

    @Override
    public int insertBatchUserTeam(Long teamId, Set<TeamMemberDTO> members) {
        if(!CollectionUtils.isEmpty(members)){
            // 封装对象集合
            Set<CommTeamUser> list = new HashSet<>();
            members.forEach(member->{
                CommTeamUser sysUserTeamEntity = new CommTeamUser(teamId,member.getUserId(),member.getName());
                list.add(sysUserTeamEntity);
            });
            return commTeamUserDao.insertBatch(list);
        }
        return 0;
    }
}
